package com.wms.project.business.itemOwner.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.wms.framework.aspectj.lang.annotation.Log;
import com.wms.framework.aspectj.lang.enums.BusinessType;
import com.wms.project.business.itemOwner.domain.ItemOwner;
import com.wms.project.business.itemOwner.service.IItemOwnerService;
import com.wms.framework.web.controller.BaseController;
import com.wms.framework.web.page.TableDataInfo;
import com.wms.framework.web.domain.AjaxResult;
import com.wms.common.utils.poi.ExcelUtil;

/**
 * 货主信息操作处理
 * 
 * @author zhangp
 * @date 2019-07-29
 */
@Controller
@RequestMapping("/business/itemOwner")
public class ItemOwnerController extends BaseController
{
    private String prefix = "business/itemOwner";
	
	@Autowired
	private IItemOwnerService itemOwnerService;
	
	@RequiresPermissions("business:itemOwner:view")
	@GetMapping()
	public String itemOwner()
	{
	    return prefix + "/itemOwner";
	}
	
	/**
	 * 查询货主列表
	 */
	@RequiresPermissions("business:itemOwner:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(ItemOwner itemOwner)
	{
		startPage();
        List<ItemOwner> list = itemOwnerService.selectItemOwnerList(itemOwner);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出货主列表
	 */
	@RequiresPermissions("business:itemOwner:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ItemOwner itemOwner)
    {
    	List<ItemOwner> list = itemOwnerService.selectItemOwnerList(itemOwner);
        ExcelUtil<ItemOwner> util = new ExcelUtil<ItemOwner>(ItemOwner.class);
        return util.exportExcel(list, "itemOwner");
    }
	
	/**
	 * 新增货主
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存货主
	 */
	@RequiresPermissions("business:itemOwner:add")
	@Log(title = "货主", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(ItemOwner itemOwner)
	{		
		return toAjax(itemOwnerService.insertItemOwner(itemOwner));
	}

	/**
	 * 修改货主
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Long id, ModelMap mmap)
	{
		ItemOwner itemOwner = itemOwnerService.selectItemOwnerById(id);
		mmap.put("itemOwner", itemOwner);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存货主
	 */
	@RequiresPermissions("business:itemOwner:edit")
	@Log(title = "货主", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(ItemOwner itemOwner)
	{		
		return toAjax(itemOwnerService.updateItemOwner(itemOwner));
	}
	
	/**
	 * 删除货主
	 */
	@RequiresPermissions("business:itemOwner:remove")
	@Log(title = "货主", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(itemOwnerService.deleteItemOwnerByIds(ids));
	}
	
}
